<?php

namespace app\mobile\controller;
//搜索
class Search extends Base
{

    public function index($navid = 'null')
    {
        if ($this->request->isGet()) {
            $table = $this->request->param('model');

            $cateInfo = db('nav')->where('model',$table)->find();
            if (!$cateInfo) {
                $this->redirect($this->request->domain());
                //$this->error('栏目不存在');
            }
            switch ($cateInfo['model']){
                case 'Supply':
                case 'Purchase':
                /*列表start*/
                $list = db($table)
                    ->where('status', '1')
                    ->where('lang',cookie('think_var'))
                    ->where('title', 'like', '%' . $this->request->param('title') . '%')
                    ->paginate()
                    ->appends($this->request->param());
                break;
                default:
                    $list = db($table)->alias('a')
                        ->join('__NAV__ c', 'c.id= a.cid')
                        ->field('a.*,c.name')
                        ->where('c.status = a.status')
                        ->where('a.status', '1')
                        ->where('a.lang = c.lang')
                        ->where('a.lang',cookie('think_var'))
                        ->where('a.title', 'like', '%' . $this->request->param('title') . '%')
                        ->paginate()
                        ->appends($this->request->param());
                    break;

            }
/*
            if($cateInfo['model']=='Supply'||$cateInfo['model']=='Purchase'){
                //列表start
                $list = db($table)
                    ->where('status', '1')
                    ->where('lang',cookie('think_var'))
                    ->where('title', 'like', '%' . $this->request->param('title') . '%')
                    ->paginate()
                    ->appends($this->request->param());
            }else{
                $list = db($table)->alias('a')
                    ->join('__NAV__ c', 'c.id= a.cid')
                    ->field('a.*,c.name')
                    ->where('c.status = a.status')
                    ->where('a.status', '1')
                    ->where('a.lang = c.lang')
                    ->where('a.lang',cookie('think_var'))
                    ->where('a.title', 'like', '%' . $this->request->param('title') . '%')
                    ->paginate()
                    ->appends($this->request->param());
//                $list = db($table)
//                    ->where('status', '1')
//                    ->where('lang',cookie('think_var'))
//                    ->where('title', 'like', '%' . $this->request->param('title') . '%')
//                    ->paginate()
//                    ->appends($this->request->param());
            }
*/

//            dump($list);
            $this->assign('list', $list);
            $this->assign('empty', lang('No relevant data'));

            /*栏目详情end*/
            $this->assign('cateInfo', $cateInfo);

            /*列表end*/
            return $this->fetch($this->template . 'search.html');
        }

    }
}
